/*
 * GLShanghui.h
 *
 *  Created on: Nov 1, 2014
 *      Author: yuliang
 */

#ifndef GLSHANGHUI_H_
#define GLSHANGHUI_H_


#include "LogicBase/GLContainerBase.h"
#include "GLGoodsCommodity.h"

class CGLShanghui : public CGLContainerBase {
public:
	typedef std::vector<CGLGoodsCommodity*>			VecCommodity_t;
public:
	CGLShanghui(const UserId_t& uid);
	virtual ~CGLShanghui();

	virtual inline void Reset() { CGLContainerBase::Reset(); m_TotalGold = 0; }
	virtual bool DecodeContainerExtend(const std::string& info);
	virtual bool EncodeContainerExtend(std::string& info);
	virtual bool DecodeGoodsExtend(uint8_t box, Index_t index, const std::string& info);
	virtual bool EncodeGoodsExtend(CGLGoodsBase*, std::string& info);

	inline void SetShanghuiInfo(const ShanghuiInfo& info) { memcpy(&m_ShanghuiInfo, &info, sizeof(info)); }
	inline const ShanghuiInfo& GetShanghuiInfo() const { return m_ShanghuiInfo; }

	inline void AddGold(const Gold_t& gold) { m_TotalGold += gold; }
	inline void DelGold(const Gold_t& gold) { m_TotalGold -= gold; }
	inline void SetTotalGold(Gold_t gold) { m_TotalGold = gold; }
	inline Gold_t GetTotalGold() const { return m_TotalGold; }

	inline int32_t ExpandShanghui(uint8_t boxSize) { return ExpandBox(boxSize); }
	inline int32_t SetCommodity(uint8_t box, Index_t index, GoodsInfo& info) { return SetGoods(box, index, info); }
	inline int32_t AddCommodity(uint8_t box, Index_t index, GoodsInfo& info) { return AddGoods(box, index, info); }
	inline CGLGoodsCommodity* GetCommodity(uint8_t box, Index_t index) { return dynamic_cast<CGLGoodsCommodity*>(GetGoods(box, index)); }
	inline int32_t RmCommodity(uint8_t box, Index_t index, Number_t num) { return RmNumGoods(box, index, num); }
	inline int32_t SwapCommodity(uint8_t firstBox, Index_t firstIndex, uint8_t secondBox, Index_t secondIndex);
	int32_t ChangePrice(uint8_t box, Index_t index, Gold_t price);
	inline void GetBoxCommodity(uint8_t box, VecCommodity_t& commodity) { GetGoods<VecCommodity_t, CGLGoodsCommodity>(box, commodity); }
	int32_t BuyCommodity(uint8_t box, Index_t index, const GoodsInfo& goods, Gold_t price);
protected:
	// 新建物品,并初始化
	virtual CGLGoodsBase* getGoods();
	virtual void setGoods(CGLGoodsBase* goods);
	virtual const GoodsFixInfo* getGoodsFixInfo(Type_t type) const;
private:
	ShanghuiInfo				m_ShanghuiInfo;
	Gold_t						m_TotalGold;
};

int32_t CGLShanghui::SwapCommodity(uint8_t firstBox, Index_t firstIndex, uint8_t secondBox, Index_t secondIndex) {
	return SwapGoods(firstBox, firstIndex, secondBox, secondIndex);
}

#endif /* GLSHANGHUI_H_ */
